package com.weblog.home.controller;

import com.weblog.home.service.HomeService;
import com.weblog.model.home.HomeChartVO;
import com.weblog.model.home.ModuleCountVo;
import entity.Result;
import entity.ResultMessage;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author MaoLin Wang
 * @date 2019/10/317:52
 */
@RequestMapping("/home")
@CrossOrigin
@RestController
public class HomeController {

    @Autowired
    private HomeService homeService;


    @PostMapping("/fetchDataInfo/{level}")
    public Result fetchDataInfo(@PathVariable("level") String level){
        List<HomeChartVO> homeChartVOS = homeService.fetchDataInfo(Integer.parseInt(level));
        return new Result(true, StatusCode.OK, ResultMessage.QUERY_SUCCESS,homeChartVOS);
    }

    /**
     * 查询各模块总记录数
     * @return
     */
    @GetMapping("/count")
    public Result count(){
        ModuleCountVo count = homeService.count();
        return new Result(true, StatusCode.OK, ResultMessage.QUERY_SUCCESS,count);
    }

    /**
     * 热门文章前20
     * @return
     */
    @PostMapping("/hot20")
    public Result fetchHot20(){
        Map<String, Object> map = homeService.fetchHot20();
        return new Result(true, StatusCode.OK, ResultMessage.QUERY_SUCCESS,map);
    }
}
